package com.ruoyi.web.controller.shop.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.entity.BO.ShopProductConfigBO;
import com.ruoyi.common.entity.VO.shop.ShopProductConfigVO;
import com.ruoyi.common.entity.VO.shop.ShopProductVO;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.web.controller.shop.mapper.IBackShopProductConfigMapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 站点-商品配置管理
 */
@Controller
@RequestMapping("/back/shopProductConfig")
public class BackShopProductConfigController extends BaseController {

    @Resource
    private IBackShopProductConfigMapper shopProductConfigMapper;

    private final String prefix = "shop/productConfig";

    /**
     * 页面-配置列表
     */
    @RequiresPermissions("back:shopProductConfig:info")
    @GetMapping("/info")
    public String info(ModelMap mmap) {
        if (0 == ShiroUtils.getShopId()) {
            return "redirect:/back/shop/switchShop";
        }
        List<ShopProductConfigVO> configList = shopProductConfigMapper.searchConfigList(ShiroUtils.getShopId(),"pay.switch");
        mmap.put("pay.switch", configList);
        return prefix + "/info";
    }

    /**
     * 数据编辑-保存配置
     *
     * @return
     */
    @Log(title = "站点-油品管理", businessType = BusinessType.UPDATE)
    @RequiresPermissions("back:shopProductConfig:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult edit(ShopProductVO shopProductVO) {
        return success();
    }
}
